﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using MedicinaMuncii.Entities;
using MedicinaMuncii.DAL.Contracts;


namespace MedicinaMuncii.Repository.Contracts
{
    /// <summary>
    /// Interface for generic repository implementations.
    /// </summary>
    /// <typeparam name="T">Class instance of <see cref="IObjectWithChangeTracker"/>.</typeparam>
    public interface IGenericRepository<T> where T : IObjectWithChangeTracker
    {
        IUnitOfWork UnitOfWork { get; }

        /// <summary>
        /// Gets an <see cref="IQueryable{T}"/> to perform further operations.
        /// </summary>
        /// <returns>An <see cref="IQueryable{T}"/>.</returns>
        IQueryable<T> GetQuery(params string[] includes);

        /// <summary>
        /// Gets an <see cref="IEnumerable{T}"/> of all elements.
        /// </summary>
        /// <returns>An <see cref="IEnumerable{T}"/> of all elements.</returns>
        IEnumerable<T> GetAll(params string[] includes);

        /// <summary>
        /// Gets an <see cref="IEnumerable{T}"/> of all elements matching the given condition.
        /// </summary>
        /// <param name="where">The condition.</param>
        /// <returns>An <see cref="IEnumerable{T}"/> of all elements matching the given condition.</returns>
        IEnumerable<T> Find(Expression<Func<T, bool>> where, params string[] includes);

        /// <summary>
        /// Gets a single instance matching the given condition.
        /// </summary>
        /// <param name="where">The condition.</param>
        /// <returns>A single instance matching the given condition.</returns>
        T Single(Expression<Func<T, bool>> where, params string[] includes);

        /// <summary>
        /// Gets a single instance matching the given condition or null if condition does not match.
        /// </summary>
        /// <param name="where">The condition.</param>
        /// <returns>A single instance matching the given condition or <c>null</c> if condition does not match.</returns>
        T SingleOrDefault(Expression<Func<T, bool>> where, params string[] includes);

        /// <summary>
        /// Adds the given entity.
        /// </summary>
        /// <param name="entity">The entity to add.</param>
        void Add(T entity);

        /// <summary>
        /// Updates the the given entity.
        /// </summary>
        /// <param name="entity">The entity to update.</param>
        void Update(T entity);

        /// <summary>
        /// Saves the the given entity.
        /// </summary>
        /// <param name="entity">The entity to update.</param>
        void Save(T entity);

        /// <summary>
        /// Deletes the given entity.
        /// </summary>
        /// <param name="entity">The entity to delete.</param>
        void Delete(T entity);
    }
}
